package com.itheima.d2_reflect_framework;

import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MyFrameWork {
    /**
     * 保存任意对象
     *
     */
    public static void save(Object o){
        try (
                PrintStream ps = new PrintStream(new FileOutputStream("data.txt",true));
                ){
            //1.获取对象
            Class c =o.getClass();
            ps.println("========================="+c.getSimpleName()+"=========================");

            //2.获取成员变量
            Field[] fields = c.getDeclaredFields();

            //3.获取成员变量信息
            for (Field field : fields) {

                String name = field.getName();
                //获取成员变量的值get
                field.setAccessible(true);
                String value = field.get(o)+"";
                ps.println(name+"="+value);

            }
        ps.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
